package top.hongthorn.config;


import com.qiniu.common.Zone;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class QiniuOSSConfig {
    @Value("${OSS.accessKey}")
    private String accessKey;
    @Value("${OSS.secretKey}")
    private String secretKey;

    private com.qiniu.storage.Configuration qnConfig() {
        return new com.qiniu.storage.Configuration(Region.region2());
    }


    @Bean
    public UploadManager uploadManager() {
        return new UploadManager(qnConfig());
    }


    @Bean
    public Auth auth() {
        return Auth.create(accessKey, secretKey);
    }


    @Bean
    public BucketManager bucketManager() {
        return new BucketManager(auth(), qnConfig());
    }
}